//
//  MineTotalPriceVC.m
//  ShandsMod
//
//  Created by zh s on 2023/3/22.
//  Copyright © 2023 zh_s. All rights reserved.
//

#import "MineTotalPriceVC.h"
#import "HomeTotalPriceCell.h"
#import "HomeAssetListCell.h"

@interface MineTotalPriceVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *mainTableView;
@property (nonatomic, strong) NSArray *dataArr;

@end

@implementation MineTotalPriceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self data_init];

    UIImageView *backV = [[UIImageView alloc] init];
    [self.view addSubview:backV];
    backV.image = IMAGE_NAME(@"bg_home_view");
    backV.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [self.view sendSubviewToBack:backV];
//    [backV.layer addSublayer:[UIColor getLeftWithRightGradualChangingColorWithViewBounds:backV fromColor:@"FFFFFF" toColor:@"C8D9FE"]];

//    UIImageView *screenImg = [[UIImageView alloc] init];
//    [self.view addSubview:screenImg];
//    screenImg.frame = CGRectMake(125, NAV_HEIGHT + 30, SCREEN_WIDTH - 125, 350);
//    screenImg.image = IMAGE_NAME(@"bg_home_screen");

    [self createCustomNavView];

    [self UI_init];

    // Do any additional setup after loading the view.
}

#pragma mark ----- UI_init
- (void)UI_init {
    [self.view addSubview:self.mainTableView];
}
#pragma mark ----- data_init
- (void)data_init {
    _dataArr = @[@"",@"",@"",@"",@"",@"",@""];
}
#pragma mark ----- tableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    }else if (section == 1) {
        return _dataArr.count;
    }
    return _dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        HomeTotalPriceCell *priceCell = [tableView dequeueReusableCellWithIdentifier:@"priceCell" forIndexPath:indexPath];
        [priceCell setMineModel:@""];
        return priceCell;
    }else {
        HomeAssetListCell *assetListCell = [tableView dequeueReusableCellWithIdentifier:@"assetListCell" forIndexPath:indexPath];
        return assetListCell;
    }

}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 8;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 130;
    }else {
        return 60;
    }
}

#pragma mark ----- 懒加载
- (UITableView *)mainTableView {
    if (!_mainTableView) {
        _mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NAV_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT -NAV_HEIGHT) style:UITableViewStyleGrouped];
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        _mainTableView.showsVerticalScrollIndicator = NO;
        _mainTableView.estimatedRowHeight = 44;//推测高度，必须有，可以随便写多少
        _mainTableView.rowHeight =UITableViewAutomaticDimension;//iOS8之后默认就是这个值，可以省略
        _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        _mainTableView.backgroundColor = UIColor.clearColor;
        [_mainTableView registerClass:[HomeTotalPriceCell class]
               forCellReuseIdentifier:@"priceCell"];
        
        [_mainTableView registerClass:[HomeAssetListCell class]
               forCellReuseIdentifier:@"assetListCell"];
        
    }
    return _mainTableView;
}

- (void)createCustomNavView {
    UIView *navHeaderV = [[UIView alloc] init];
    [self.nav addSubview:navHeaderV];
    [navHeaderV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.nav);
    }];
    navHeaderV.backgroundColor = [UIColor clearColor];

    
    UIButton *createBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [navHeaderV addSubview:createBtn];
    [createBtn addTarget:self action:@selector(createWallet) forControlEvents:UIControlEventTouchUpInside];
    //默认是YES高亮效果
    [createBtn setAdjustsImageWhenHighlighted:NO];
    [createBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(27);
        make.centerY.mas_equalTo(self.nav.titleLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(10, 18));
    }];
    [createBtn setBackgroundImage:IMAGE_NAME(@"Icon_Navigation Bar_Back") forState:UIControlStateNormal];
    
    UILabel *titleLab = [[UILabel alloc] init];
    [navHeaderV addSubview:titleLab];
    titleLab.textColor = MAIN_BACKCOLOR;
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.font = FONT_NAME(FONT_Semibold, 18);
    titleLab.text = @"资产总览";
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.nav.mas_centerX);
        make.top.mas_equalTo(STATUS_BAR_HEIGHT +10);
        make.left.right.equalTo(self.nav.titleLabel);
    }];
    
    self.nav.backgroundColor = UIColor.clearColor;
    self.leftTitle = @"";
}

- (void)createWallet {
    [self.navigationController popViewControllerAnimated:YES];
}


@end
